function cherryCount(m, n, arr) {
    let ans = 0;
    let tree = new Array(m);
    let token;
    for (let i = 0; i < m; i++) {
        tree[i] = []
    }
    for (let i = 0; i < arr.length; i++) {
        token = arr[i].split(' ')
        tree[token[0] - 1].push(token[2])
    }
    console.log(tree, "tree");
    let num;
    for (let i = 0; i < arr.length; i++) {
        if (tree[i].length == 2) {
            num = tree[i].reduce((pre, cur) => {
                return pre + tree[cur - 1].length
            }, 0)
            if (num == 0) ans++
        }

    }
    return ans;
}
let test = [
    '1 left 2',
    '1 right 3',
    '2 left 4',
    '2 right 5',
    '3 right 6',
    '6 left 7',
    '6 right 8',
    '7 left 9',
    '7 right 10'
]
console.log(cherryCount(10, 9, test))